
/*
 * Desenvolvimento para WEB
 * 
 * NOME: Vitor Augusto Graciani           RA: 345270
 * NOME: Felipe Petruz Brina              RA: 345083
 * NOME: Diego Zamboni Latance            RA: 344990
 * NOME: Rafael Claudio Domene            RA: 345040
 * NOME: Vinicius Rodrigues de Campos     RA: 345350
 * 
 */


package auxiliar;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import model.*;


public class ConnectionFactory {

    public static Connection getConnection() throws DAOException {
        try {
            //A arrumar... ********************************************************************************
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
            String conexao = "jdbc:sqlserver://localhost:1433;databasename=labbd01";
            String usuario = "sa", senha = "felipe123";
            Connection conn = DriverManager.getConnection(conexao, usuario, senha);
            return conn;
        } catch (Exception e) {
            throw new DAOException(e.getMessage());
        }
    }

    public static void closeConnection(Connection conn, Statement stmt, ResultSet rs)
            throws DAOException {
        close(conn, stmt, rs);
    }

    public static void closeConnection(Connection conn, Statement stmt)
            throws DAOException {
        close(conn, stmt, null);
    }

    public static void closeConnection(Connection conn)
            throws DAOException {
        close(conn, null, null);
    }

    private static void close(Connection conn, Statement stmt, ResultSet rs)
            throws DAOException {
        try {
            if (rs != null) {
                rs.close();
            }
            if (stmt != null) {
                stmt.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e) {
            throw new DAOException(e.getMessage());
        }
    }
}
